import Context from "../../../framework/Context";
import {MVS_MSG} from "./MatvhsvsMessage";

/**
 * 网络通信结果通知。主要用于联机通信。不同的通信底层可用此类继承适配。
 */
export class MatchResponse {
    private notifier: any = null;
    private context: Context = null;
    private _isInited: boolean = false;
    private _isLogined: boolean = false;

    constructor(notifier: any, context: Context) {
        this.notifier = notifier;
        this.context = context;
    }

    public bind() {
        this.notifier.initResponse = this.initResponse.bind(this);
        this.notifier.registerUserResponse = this.registerUserResponse.bind(this);
        this.notifier.loginResponse = this.loginResponse.bind(this);
        this.notifier.logoutResponse = this.logoutResponse.bind(this);

        this.notifier.reconnectResponse = this.reconnectResponse.bind(this);
        this.notifier.errorResponse = this.errorResponse.bind(this);
        this.notifier.joinRoomResponse = this.joinRoomResponse.bind(this);
        this.notifier.joinRoomNotify = this.joinRoomNotify.bind(this);
        this.notifier.leaveRoomResponse = this.leaveRoomResponse.bind(this);
        this.notifier.leaveRoomNotify = this.leaveRoomNotify.bind(this);
        this.notifier.joinOverResponse = this.joinOverResponse.bind(this);
        this.notifier.joinOverNotify = this.joinOverNotify.bind(this);
        this.notifier.sendEventResponse = this.sendEventResponse.bind(this);
        this.notifier.sendEventNotify = this.sendEventNotify.bind(this);

        // ========================
        this.notifier.kickPlayerResponse = this.kickPlayerResponse.bind(this);
        this.notifier.kickPlayerNotify = this.kickPlayerNotify.bind(this);
        this.notifier.joinOpenResponse = this.joinOpenResponse.bind(this);
        this.notifier.joinOpenNotify = this.joinOpenNotify.bind(this);
        this.notifier.getRoomListExResponse = this.getRoomListExResponse.bind(this);
        this.notifier.getRoomDetailResponse = this.getRoomDetailResponse.bind(this);
        this.notifier.createRoomResponse = this.createRoomResponse.bind(this);
        this.notifier.setRoomPropertyResponse = this.setRoomPropertyResponse.bind(this);
        this.notifier.setRoomPropertyNotify = this.setRoomPropertyNotify.bind(this);
        this.notifier.networkStateNotify = this.networkStateNotify.bind(this);
        this.notifier.subscribeEventGroupResponse = this.subscribeEventGroupResponse.bind(this);
        this.notifier.sendEventGroupResponse = this.sendEventGroupResponse.bind(this);
        this.notifier.sendEventGroupNotify = this.sendEventGroupNotify.bind(this);
        this.notifier.frameUpdate = this.frameUpdate.bind(this);
        this.notifier.gameServerNotify = this.gameServerNotify.bind(this);
        this.notifier.setFrameSyncResponse = this.setFrameSyncResponse.bind(this);
        this.notifier.setFrameSyncNotify = this.setFrameSyncNotify.bind(this);
        this.notifier.sendFrameEventResponse = this.sendFrameEventResponse.bind(this);
        this.notifier.getOffLineDataResponse = this.getOffLineDataResponse.bind(this);
        this.notifier.getWatchRoomsResponse = this.getWatchRoomsResponse.bind(this);
        this.notifier.joinWatchRoomNotify = this.joinWatchRoomNotify.bind(this);
        this.notifier.joinWatchRoomResponse = this.joinWatchRoomResponse.bind(this);

        this.notifier.leaveWatchRoomResponse = this.leaveWatchRoomResponse.bind(this);
        this.notifier.leaveWatchRoomNotify = this.leaveWatchRoomNotify.bind(this);
        this.notifier.setLiveOffsetResponse = this.setLiveOffsetResponse.bind(this);
        this.notifier.liveFrameUpdate = this.liveFrameUpdate.bind(this);
        this.notifier.changeRoleResponse = this.changeRoleResponse.bind(this);
        this.notifier.cancelTeamMatchResponse = this.cancelTeamMatchResponse.bind(this);
        this.notifier.cancelTeamMatchNotify = this.cancelTeamMatchNotify.bind(this);
    }

    public unbind() {
        this.notifier.initResponse = null;
        this.notifier.registerUserResponse = null;
        this.notifier.loginResponse = null;
        this.notifier.reconnectResponse = null;
        this.notifier.errorResponse = null;
        this.notifier.joinRoomResponse = null;
        this.notifier.joinRoomNotify = null;
        this.notifier.leaveRoomResponse = null;
        this.notifier.leaveRoomNotify = null;
        this.notifier.joinOverResponse = null;
        this.notifier.joinOverNotify = null;
        this.notifier.sendEventResponse = null;
        this.notifier.sendEventNotify = null;

        this.notifier.kickPlayerResponse = null;
        this.notifier.kickPlayerNotify = null;
        this.notifier.joinOpenResponse = null;
        this.notifier.joinOpenNotify = null;
        this.notifier.getRoomListExResponse = null;
        this.notifier.getRoomDetailResponse = null;
        this.notifier.createRoomResponse = null;
        this.notifier.setRoomPropertyResponse = null;
        this.notifier.setRoomPropertyNotify = null;
        this.notifier.networkStateNotify = null;
        this.notifier.subscribeEventGroupResponse = null;
        this.notifier.frameUpdate = null;
        this.notifier.gameServerNotify = null;
        this.notifier.setFrameSyncResponse = null;
        this.notifier.setFrameSyncNotify = null;
        this.notifier.sendFrameEventResponse = null;
        this.notifier.getOffLineDataResponse = null;
        this.notifier.sendEventGroupResponse = null;
        this.notifier.sendEventGroupNotify = null;
        this.notifier.getWatchRoomsResponse = null;

        this.notifier.joinWatchRoomNotify = null;
        this.notifier.joinWatchRoomResponse = null;

        this.notifier.leaveWatchRoomResponse = null;
        this.notifier.leaveWatchRoomNotify = null;
        this.notifier.setLiveOffsetResponse = null;
        this.notifier.liveFrameUpdate = null;
        this.notifier.changeRoleResponse = null;
        this.notifier.cancelTeamMatchResponse = null;// this.cancelTeamMatchResponse.bind(this);
        this.notifier.cancelTeamMatchNotify = null;// this.cancelTeamMatchNotify.bind(this);

    }

    public get isInit(): boolean {
        return this._isInited;
    }

    public get isLogin(): boolean {
        return this._isLogined;
    }

    public initResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.INIT, args);
        if (args[0] == 0) {
            this._isInited = true;
        }
    }

    public registerUserResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.REGISTER_USER, args);
    }

    public loginResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.LOGIN, args);
        if (args[0] == 200) {
            this._isLogined = true;
        }
    }

    public logoutResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.LOGOUT, args);
    }

    public reconnectResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.RE_CONNECT, args);
    }

    public errorResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.ERROR_MSG, args);
    }

    public joinRoomResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.JOIN_ROOM_RSP, args);
    }

    public joinRoomNotify() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.JOIN_ROOM_NOTIFY, args);
    }

    public leaveRoomResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.LEAVE_ROOM, args);
    }

    public leaveRoomNotify() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.LEAVE_ROOM_NOTIFY, args);
    }

    public joinOverResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.JOIN_OVER_RSP, args);
    }

    public joinOverNotify() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.JOIN_OVER_NOTIFY, args);
    }

    public sendEventResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.SEND_EVENT_RSP, args);
    }

    public sendEventNotify() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.SEND_EVENT_NOTIFY, args);
    }

    //===============================

    public kickPlayerResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.KICK_PLAYER, args);
    }

    public kickPlayerNotify() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.KICK_PLAYER_NOTIFY, args);
    }

    public joinOpenResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.JOIN_OPEN_RSP, args);
    }

    public joinOpenNotify() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.JOIN_OPEN_NOTIFY, args);
    }

    public getRoomListExResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.ROOM_LIST_EX, args);
    }

    public getRoomDetailResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.ROOM_DETAIL, args);
    }

    public createRoomResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.CREATE_ROOM, args);
    }

    public setRoomPropertyResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.SET_ROOM_PROPERTY, args);
    }

    public setRoomPropertyNotify() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.SET_ROOM_PROPERTY_NOTIFY, args);
    }

    public networkStateNotify() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.NETWORK_STATE_NOTIFY, args);
    }

    public subscribeEventGroupResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.EVENT_GROUP_SUB, args);
    }

    public frameUpdate() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.FRAME_UPDATE, args);
    }

    public gameServerNotify() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.SERVER_NOTIFY, args);
    }

    public setFrameSyncResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.SET_FRAME_SYNC, args);
    }

    public setFrameSyncNotify() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.SET_FRAME_SYNC_NOTIFY, args);
    }

    public sendFrameEventResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.SEND_FRAME_EVENT, args);
    }

    public getOffLineDataResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.GET_OFFLINE_DATA, args);
    }

    public sendEventGroupResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.SEND_EVENT_GROUP, args);
    }

    public sendEventGroupNotify() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.SEND_EVENT_GROUP_NOTIFY, args);
    }

    public getWatchRoomsResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.SEND_EVENT_GROUP_NOTIFY, args);
    }

    public joinWatchRoomResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.JOIN_WATCH_ROOM, args);
    }

    public joinWatchRoomNotify() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.JOIN_WATCH_ROOM_NOTIFY, args);
    }

    public leaveWatchRoomResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.LEAVE_WATCH_ROOM, args);
    }

    public leaveWatchRoomNotify() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.LEAVE_WATCH_ROOM_NOTIFY, args);
    }

    public setLiveOffsetResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.SET_LIVE_OFFSET, args);
    }

    public liveFrameUpdate() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.LIVE_FRAME_UPDATE, args);
    }

    public changeRoleResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.LIVE_FRAME_UPDATE, args);
    }

    public cancelTeamMatchResponse() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.LIVE_FRAME_UPDATE, args);

    }

    public cancelTeamMatchNotify() {
        const args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
        this.context.messenger.sendMessage(MVS_MSG.LIVE_FRAME_UPDATE, args);

    }
}
